﻿using DevComponents.DotNetBar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WorkStation.UI.Controls
{
    public partial class MyMessageBoxEx : Office2007Form
    {
        public MessageBoxResult Result { get; set; }
        public MyMessageBoxEx()
        {
            InitializeComponent();
            this.EnableGlass = false;
        }
        public void SetCaption(string caption)
        {
            this.Text = caption;
        }
        public void SetMessage(string message)
        {
            this.l_Message.Text = message;
        }
        public void SetButton(List<string> buttonText)
        {
            switch (buttonText.Count)
            {
                case 0:
                    break;
                case 1:
                    this.btn_First.Visible = false;
                    this.btn_Third.Visible = false;
                    this.btn_Second.Visible = true;
                    this.btn_Second.Text = buttonText[0];
                    break;
                case 2:
                    this.btn_First.Visible = true;
                    this.btn_Third.Visible = true;
                    this.btn_Second.Visible = false;
                    this.btn_First.Text = buttonText[0];
                    this.btn_Third.Text = buttonText[1];
                    break;
                case 3:
                    this.btn_First.Visible = true;
                    this.btn_Third.Visible = true;
                    this.btn_Second.Visible = true;
                    this.btn_First.Text = buttonText[0];
                    this.btn_Second.Text = buttonText[1];
                    this.btn_Third.Text = buttonText[2];
                    break;
            }
        }
        public void SetImage(MessageBoxType messageType)
        {
            switch(messageType)
            {
                case MessageBoxType.Info:
                    this.l_Message.Image = Properties.Resources.Information;
                    break;
                case MessageBoxType.Warn:
                    this.l_Message.Image = Properties.Resources.Warn;
                    break;
                case MessageBoxType.Question:
                    this.l_Message.Image = Properties.Resources.Question;
                    break;
            }
        }
        public static MessageBoxResult ShowBox(string message, string caption, List<string> buttonText, MessageBoxType messageType)
        {
            MyMessageBoxEx box = new MyMessageBoxEx();
            box.SetCaption(caption);
            box.SetMessage(message);
            box.SetButton(buttonText);
            box.StartPosition = FormStartPosition.CenterParent;
            if (box.ShowDialog() == DialogResult.Cancel)
                return MessageBoxResult.Cancel;
            return box.Result;
        }

        private void btn_First_Click(object sender, EventArgs e)
        {
            this.Result = MessageBoxResult.First;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btn_Second_Click(object sender, EventArgs e)
        {
            this.Result = MessageBoxResult.Second;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btn_Third_Click(object sender, EventArgs e)
        {
            this.Result = MessageBoxResult.Third;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
    public enum MessageBoxType
    {
        Info,
        Warn,
        Question,
    }
    public enum MessageBoxResult
    {
        Cancel,
        First,
        Second,
        Third,
    }
}
